//
//  NSString+EX.m
//  iSee
//
//  Created by 刘琛 on 2019/5/5.
//  Copyright © 2019年 刘琛. All rights reserved.
//

#import "NSString+EX.h"
# include <arpa/inet.h>

@implementation NSString (EX)

+ (NSString *)URLEncodedString:(NSString *) urlStr {
    
     return[urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

}

+ (NSString *)URLDecodedString:(NSString *)urlStr {
    
    return [urlStr stringByRemovingPercentEncoding];
}

+ (NSString *)translateDeviceToken:(NSData *)deviceTokenData {

    NSUInteger len = [deviceTokenData length];
    char *chars = (char *)[deviceTokenData bytes];
    NSMutableString *hexString = [[NSMutableString alloc] init];
    for (NSUInteger i = 0; i < len; i++) {
        [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]];
    }
    
    return hexString;
    
}

@end
